package com.droidexchange.custom;

import java.text.SimpleDateFormat;
import net.sf.stackwrap4j.entities.Question;
import net.sf.stackwrap4j.entities.User;
import net.sf.stackwrap4j.utils.StackUtils;
import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.droidexchange.R;
import com.droidexchange.main.DeMajorPost;

public class QuestionTab extends RelativeLayout
{
	public QuestionTab(Context context)
	{
		this(context, null);
	}

	public QuestionTab(Context context, AttributeSet attrs)
	{
		this(context, attrs, 0);
	}

	public QuestionTab(Context context, AttributeSet attrs, int defStyle)
	{
		super(context, attrs, defStyle);
		((Activity) getContext()).getLayoutInflater().inflate(R.layout.question_tab, this, true);
	}

	public void setViewContents(DeMajorPost post)
	{
		User user = post.majorPost.getOwner();
		if (user != null)
		{
			// ImageView imgGravatar =
			// (ImageView)findViewById(R.id.img_gravatar);
			TextView txtName = (TextView) findViewById(R.id.name);
			txtName.setText(user.getDisplayName());

			TextView txtreputation = (TextView) findViewById(R.id.reputation);
			txtreputation.setText(Integer.toString(user.getReputation()));
		}

		TextView txtAction = (TextView) findViewById(R.id.action);
		txtAction.setText(post.majorPost instanceof Question ? "asked" : "answered");

		SimpleDateFormat sdf = new SimpleDateFormat();
		TextView txtDateTime = (TextView) findViewById(R.id.date_time);
		txtDateTime.setText(StackUtils.formatElapsedTime(post.majorPost.getCreationDate()));

	}
}
